﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbXRefMan : IDisposable
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbXRefMan(IntPtr cPtr, bool cMemoryOwn)
		{
			this.swigCMemOwn = cMemoryOwn;
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbXRefMan obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbXRefMan()
		{
			this.Dispose();
		}

		public virtual void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbXRefMan(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
		}

		public static OdResult load(OdDbDatabase pHostDb, string xrefBlockname)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXRefMan_load__SWIG_0(OdDbDatabase.getCPtr(pHostDb), xrefBlockname);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdResult load(OdDbObjectIdArray xrefBTRids)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXRefMan_load__SWIG_1(OdDbObjectIdArray.getCPtr(xrefBTRids));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdResult load(OdDbBlockTableRecord pBTR)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXRefMan_load__SWIG_2(OdDbBlockTableRecord.getCPtr(pBTR));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdResult loadAll(OdDbDatabase pHostDb, bool verify)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXRefMan_loadAll__SWIG_0(OdDbDatabase.getCPtr(pHostDb), verify);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdResult loadAll(OdDbDatabase pHostDb)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXRefMan_loadAll__SWIG_1(OdDbDatabase.getCPtr(pHostDb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static void unload(OdDbBlockTableRecord pBTR)
		{
			TD_DbPINVOKE.OdDbXRefMan_unload__SWIG_0(OdDbBlockTableRecord.getCPtr(pBTR));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public static void unload(OdDbObjectIdArray xrefBTRids)
		{
			TD_DbPINVOKE.OdDbXRefMan_unload__SWIG_1(OdDbObjectIdArray.getCPtr(xrefBTRids));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public static void unloadAll(OdDbDatabase pHostDb)
		{
			TD_DbPINVOKE.OdDbXRefMan_unloadAll(OdDbDatabase.getCPtr(pHostDb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public static OdResult bind(OdDbBlockTableRecord pBTR, bool insertBind)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXRefMan_bind__SWIG_0(OdDbBlockTableRecord.getCPtr(pBTR), insertBind);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdResult bind(OdDbBlockTableRecord pBTR)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXRefMan_bind__SWIG_1(OdDbBlockTableRecord.getCPtr(pBTR));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdResult detach(OdDbBlockTableRecord pBTR)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXRefMan_detach(OdDbBlockTableRecord.getCPtr(pBTR));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static void setOverlaid(OdDbBlockTableRecord pBTR, bool overlaid)
		{
			TD_DbPINVOKE.OdDbXRefMan_setOverlaid__SWIG_0(OdDbBlockTableRecord.getCPtr(pBTR), overlaid);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public static void setOverlaid(OdDbBlockTableRecord pBTR)
		{
			TD_DbPINVOKE.OdDbXRefMan_setOverlaid__SWIG_1(OdDbBlockTableRecord.getCPtr(pBTR));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdDbXRefMan() : this(TD_DbPINVOKE.new_OdDbXRefMan(), true)
		{
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		protected bool swigCMemOwn;
	}
}
